package com.mulanweb.handler;

import net.coobird.thumbnailator.Thumbnails;
import org.jsoup.helper.StringUtil;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/14 0014.
 */
public class PhotoHandler {


    public static boolean thumbnails(List<String> photoNames){
        int i = 0;
        int f = 0;
        List<String> non_existent = new ArrayList<>();
        try {
            for (String name : photoNames) {
                String photoPath = "D:/website/mulan_xxl/static/view-img/" + name;
                File photo = new File(photoPath);
                if (photo.exists()){
                    Thumbnails.of(photoPath)
                            .size(240, 160)
                            .toFile("D:/website/mulan_xxl/static/view-img/test/" + name);
                }else{
                    f++;
                    non_existent.add(name);
                }
                i++;
                System.out.println("---已处理：" + i + "张图片"+";不能存在："+f+"张图片");
            }
            System.out.println("-----------共处理：" + i + "张图片"+";不能存在："+f+"张图片");
            System.out.println(StringUtil.join(non_existent,","));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("-----------共处理：" + i + "张图片"+";不能存在："+f+"张图片");
            System.out.println(StringUtil.join(non_existent,","));
        }

        return false;
    }

    public static boolean thumbnails(String photoName){
        List<String> list = new ArrayList<>();
        list.add(photoName);
        return thumbnails(list);
    }


}
